'use strict';

const Controller = require('egg').Controller;
class UserController extends Controller {
  async zc() {
    const { ctx } = this;
   //获取到输入的内容
   let {username,pwd,name,email}=ctx.request.body
   //费控验证
   if(!username||!pwd||!name||!email)
   {
       ctx.body={
           code:0,
           msg:"请将内容正确的输入完"
       }
   }
   else if(/^[0-9A-Za-z]{5,}$/.test(username))
   {
        //将数据传入
        let res= await ctx.service.user.yz(username)
       //判断为空
       if(res.length==[])
       {
        let res= await ctx.service.user.zc(username,ctx.helper.help(pwd) ,name,email)
            ctx.body={
                msg:"注册成功",
                code:1
            }
       }
       else{
        ctx.body={
            code:0,
            msg:"注册失败"
        }
       }
   }
   else{
    ctx.body={
        code:0,
        msg:"账户不能小于5"
    }
   }
  }
  async login ()
  {
      let {ctx}=this
      let {username,pwd}=ctx.request.body
      if(!username||!pwd)
        {
            ctx.body={
                code:0,
                msg:"请将内容正确的输入完"
            }
        }
    console.log(username,pwd)
    let res=await ctx.service.user.login(username,ctx.helper.help(pwd))
   //判断长度
   if(res.length)
   {
       ctx.body={
           code:0,
           mag:"登陆成功"
       }
   }
   else{
    ctx.body={
        code:0,
        mag:"登陆失败"
    }
   }
  }
}

module.exports = UserController;